//
//  MYGAddScheduleViewController.swift
//  MYGrow
//
//  Created by 王振明 on 2024/3/16.
//

import UIKit
import DGCollectionViewLeftAlignFlowLayout
import TZImagePickerController
import Foundation

class MYGAddScheduleViewController: MYGBaseController {
    // MARK: - Property
    var startTime:Date = Date()
    var endTime:Date = Date()
    private var contents: [String] = []
    var model:MYGScheduleListModel = MYGScheduleListModel(){
        didSet{
            titleTf.text = model.name
            startTimeLabel.text = model.start_at
            endTimeLabel.text = model.end_at
            allDaySwitchView.switchBtn.isSelected = model.time_type == 1 ? true : false
            backColorSwitchView.switchBtn.isSelected = model.is_color > 0 ? true : false
            selfSeeSwitchView.switchBtn.isSelected = model.self_visible > 0 ? true : false
            huiyiPingtaiView.contentSubLab.text = model.schedule_type
            huiyihaoView.inputTf.text = model.schedule_number
            huichangView.inputTf.text = model.schedule_site
            jiangtiView.inputTf.text = model.schedule_theme
            remindView.contentSubLab.text = model.remind_time_desc
            remindView.contentSubLab.textColor = .rgba(51, 51, 51)
            huiyiAdressView.inputTf.text = model.schedule_address
            contentTextView.text = model.describe
            allDaySwitchView.switchBtn.isSelected = model.time_type == 1 ? true : false
            levelView.contentSubLab.text = model.status == 1 ? "紧急" : "普通"
            levelView.contentSubLab.textColor = .rgba(51, 51, 51)
            scheduleTypeVi.defaultSelectAction(model: model)
            jueseView.defaultSelectAction(model: model)
            if model.image.count > 0{
                guard let jsonData = model.image.data(using: .utf8) else {
                    fatalError("Failed to convert JSON string to data.")
                }
                do {
                    // 将JSON数据反序列化为Foundation对象
                    guard let jsonObject = try JSONSerialization.jsonObject(with: jsonData, options: []) as? [String] else {
                        fatalError("Failed to deserialize JSON data.")
                    }
                    model.imageStrArr = [jsonObject[0]]
                } catch {
                    print("Error: \(error)")
                }
            }

            switch model.type {
            case "线上会议":
                //线上会议
                jueseView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                huiyiPingtaiView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                huiyihaoView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                huichangView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                jiangtiView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                huiyiAdressView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                break
            case "线下会议":
                //线下会议
                jueseView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                huiyiPingtaiView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                huiyihaoView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                huichangView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                jiangtiView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                huiyiAdressView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                break
            default:
                jueseView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                huiyiPingtaiView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                huiyihaoView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                huichangView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                jiangtiView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                huiyiAdressView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                huichangView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                break
            }
            collectionView.reloadData()
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        self.title = "新建日程"
        configNormalUI()
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let barBtnItem:UIBarButtonItem = UIBarButtonItem(customView: backBtn)
        self.navigationItem.leftBarButtonItem = barBtnItem
    }
    private func configNormalUI(){
        // 通过UIColor对象设置导航栏的背景颜色
        navigationController?.navigationBar.barTintColor = UIColor.clear
        navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white]
        view.addSubview(headImageV)
        headImageV.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.height.equalTo(statusBarHeight + 44)
            make.top.equalToSuperview().offset(-statusBarHeight - 44)
        }
        view.addSubview(scView)
        scView.snp.makeConstraints { make in
            make.bottom.equalToSuperview().offset(-96)
            make.left.top.right.equalToSuperview()
        }
        scView.addSubview(scContanerView)
        scContanerView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
            make.width.equalTo(screenWidth)
        }
        scContanerView.addSubview(titleTf)
        titleTf.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(65)
        }
        scContanerView.addSubviews([startTimeView,endTimeView])
        startTimeView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(27)
            make.top.equalTo(titleTf.snp.bottom)
            make.height.equalTo(70)
            make.width.equalTo((screenWidth - 64)/2)
        }
        endTimeView.snp.makeConstraints { make in
            make.left.equalTo(startTimeView.snp.right).offset(10)
            make.top.equalTo(titleTf.snp.bottom)
            make.height.equalTo(70)
            make.width.equalTo((screenWidth - 64)/2)
        }
        scContanerView.addSubview(allDaySwitchView)
        allDaySwitchView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(endTimeView.snp.bottom).offset(12.5)
            make.height.equalTo(50)
        }
        scContanerView.addSubview(levelView)
        levelView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(allDaySwitchView.snp.bottom)
            make.height.equalTo(50)
        }
        scContanerView.addSubview(scheduleTypeVi)
        scheduleTypeVi.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(levelView.snp.bottom)
            make.height.equalTo(50)
        }
        scContanerView.addSubview(backColorSwitchView)
        backColorSwitchView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(scheduleTypeVi.snp.bottom)
            make.height.equalTo(50)
        }
        scContanerView.addSubview(jueseView)
        jueseView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(backColorSwitchView.snp.bottom)
            make.height.equalTo(0)
        }
        scContanerView.addSubview(huiyiAdressView)
        huiyiAdressView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(jueseView.snp.bottom)
            make.height.equalTo(0)
        }
        scContanerView.addSubview(huiyiPingtaiView)
        huiyiPingtaiView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(huiyiAdressView.snp.bottom)
            make.height.equalTo(0)
        }
        scContanerView.addSubview(huiyihaoView)
        huiyihaoView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(huiyiPingtaiView.snp.bottom)
            make.height.equalTo(0)
        }
        scContanerView.addSubview(huichangView)
        huichangView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(huiyihaoView.snp.bottom)
            make.height.equalTo(0)
        }
        scContanerView.addSubview(jiangtiView)
        jiangtiView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(huichangView.snp.bottom)
            make.height.equalTo(0)
        }
        scContanerView.addSubview(remindView)
        remindView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(jiangtiView.snp.bottom)
            make.height.equalTo(50)
        }
        scContanerView.addSubview(selfSeeSwitchView)
        selfSeeSwitchView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(remindView.snp.bottom)
            make.height.equalTo(50)
        }
        scContanerView.addSubview(contentTextView)
        contentTextView.snp.makeConstraints { make in
            make.top.equalTo(selfSeeSwitchView.snp.bottom)
            make.right.equalToSuperview().offset(-SCALEWIDTH(25))
            make.left.equalToSuperview().offset(SCALEWIDTH(25))
            make.height.equalTo(93)
        }
        scContanerView.addSubview(collectionView)
        collectionView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().offset(26)
            make.top.equalTo(contentTextView.snp.bottom)
            make.height.equalTo(90)
            make.bottom.equalToSuperview().offset(-20)
        }
        view.addSubview(sureBtn)
        sureBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(54)
            make.right.equalToSuperview().offset(-54)
            make.bottom.equalToSuperview().offset(-36)
            make.top.equalTo(scView.snp.bottom).offset(20)
        }
    }
    //创建日程
    @objc func doneAction() {
        if model.id > 0{
            editAction()
            return
        }
        if (model.name.count == 0){
            MMYGHUD.showToast(text: "请填写标题")
            return
        }
        if (model.start_at.count == 0){
            MMYGHUD.showToast(text: "请选择开始时间")
            return
        }
        MYGLoading.show()
        var params:[String:Any] = [:]
        if model.type == "线上会议" {
            params["task"] = model.task
            params["schedule_type"] = model.schedule_type
            params["schedule_number"] = model.schedule_number
            params["schedule_site"] = model.schedule_site
            params["schedule_theme"] = model.schedule_theme
        }else if model.type == "线下会议"{
            params["task"] = model.task
            params["schedule_address"] = model.schedule_address
            params["schedule_site"] = model.schedule_site
            params["schedule_theme"] = model.schedule_theme
        }
        params["name"] = model.name
        params["type"] = model.type
        params["describe"] = model.describe
        params["time_type"] = model.time_type
//        if model.time_type != 1{
//            params["start_at"] = getUpdateTimehhmmByDate(date: startTime)
//            params["end_at"] = getUpdateTimehhmmByDate(date: endTime)
//        }else{
            params["start_at"] = model.start_at
            params["end_at"] = model.end_at
//        }
        params["status"] = model.status
        params["is_color"] = model.is_color
        params["remind_time_desc"] = model.remind_time_desc
        if model.imageStrArr.count > 0{
            if let jsonData = try? JSONSerialization.data(withJSONObject: model.imageStrArr, options: []) {
                // 将JSON数据转换为String以便打印或者查看
                if let jsonString = String(data: jsonData, encoding: .utf8) {
                    params["image"] = jsonString
                }
            } else {
                print("转换JSON时发生错误")
            }
        }

//        let dateformatter = DateFormatter()
//        dateformatter.dateFormat = "YYYY-MM-dd"
//        let dateStr = dateformatter.string(from: Date())
        params["set_date"] = model.set_date
        params["remind_date_time"] = model.remind_date_time
        params["remind_date_5"] = model.remind_date_5
        params["remind_date_10"] = model.remind_date_10
        params["remind_date_30"] = model.remind_date_30
        params["remind_date_60"] = model.remind_date_60
        params["remind_date_one_day"] = model.remind_date_one_day
        params["remind_time_type"] = model.remind_time_type

        MYGNetwork<MYGScheduleAPI, MYGEmptyModel>.request(target: MYGScheduleAPI.addSchedule(params: params)) { result in
            MYGLoading.hide()
            MMYGHUD.showToast(text: "添加成功")
            NotificationCenter.default.post(name: NSNotification.Name.init("MYGScheduleRefresh"), object: nil)
            self.navigationController?.popViewController()
        } failed: { _, error in
            MYGLoading.hide()
            MMYGHUD.showToast(text: error)
        }
    }
    //编辑日程
    @objc func editAction() {
        if (model.name.count == 0){
            MMYGHUD.showToast(text: "请填写标题")
            return
        }
        if (model.start_at.count == 0){
            MMYGHUD.showToast(text: "请选择开始时间")
            return
        }
        MYGLoading.show()
        var params:[String:Any] = [:]
        if model.type == "线上会议" {
            params["task"] = model.task
            params["schedule_type"] = model.schedule_type
            params["schedule_number"] = model.schedule_number
            params["schedule_site"] = model.schedule_site
            params["schedule_theme"] = model.schedule_theme
        }else if model.type == "线下会议"{
            params["task"] = model.task
            params["schedule_address"] = model.schedule_address
            params["schedule_site"] = model.schedule_site
            params["schedule_theme"] = model.schedule_theme
        }
        params["name"] = model.name
        params["type"] = model.type
        params["describe"] = model.describe

        params["time_type"] = model.time_type
        params["status"] = model.status
        params["is_color"] = model.is_color
        params["remind_time_desc"] = model.remind_time_desc
        if model.imageStrArr.count > 0{
            if let jsonData = try? JSONSerialization.data(withJSONObject: model.imageStrArr, options: []) {
                // 将JSON数据转换为String以便打印或者查看
                if let jsonString = String(data: jsonData, encoding: .utf8) {
                    params["image"] = jsonString
                }
            } else {
                print("转换JSON时发生错误")
            }
        }

//        let dateformatter = DateFormatter()
//        dateformatter.dateFormat = "YYYY-MM-dd"
//        let dateStr = dateformatter.string(from: Date())
//        if model.time_type != 1{
            params["start_at"] = model.start_at
            params["end_at"] = model.end_at
//        }else{
//            params["start_at"] = timeTozeroTime(timeStr: model.start_at)
//            params["end_at"] = timeTozeroTime(timeStr: model.end_at)
//        }
        params["set_date"] = model.set_date
        params["remind_date_time"] = model.remind_date_time
        params["remind_date_5"] = model.remind_date_5
        params["remind_date_10"] = model.remind_date_10
        params["remind_date_30"] = model.remind_date_30
        params["remind_date_60"] = model.remind_date_60
        params["remind_date_one_day"] = model.remind_date_one_day
        params["remind_time_type"] = model.remind_time_type
        params["id"] = model.id

        MYGNetwork<MYGScheduleAPI, MYGScheduleListModel>.request(target: MYGScheduleAPI.editSchedule(param: params)) {[weak self] result in
            MYGLoading.hide()
            MMYGHUD.showToast(text: "修改成功")
            NotificationCenter.default.post(name: NSNotification.Name.init("MYGScheduleRefresh"), object: self?.model)
            self?.navigationController?.popToRootViewController(animated: true)
        } failed: { _, error in
            MYGLoading.hide()
            MMYGHUD.showToast(text: error)
        }
    }
    //MARK: lazy
    lazy var backBtn: UIButton = {
        let control = UIButton(type: .custom)
        control.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
        control.tintColor = .white
        control.setImage(UIImage(named: "Chat/back"), for: .normal)
        control.addTarget(self, action: #selector(backAction), for: .touchUpInside)
        return control
    }()
    private lazy var scView:UIScrollView = {
        let cont = UIScrollView()
        return cont
    }()
    private lazy var scContanerView:UIView = {
        let cont = UIView()
        return cont
    }()
    private lazy var titleTf:UITextField = {
        let cont = UITextField()
        cont.backgroundColor = .clear
        cont.placeholder = "请输入事件标题"
        cont.font = .regular(24)
        let leftView1 = UIView(frame: CGRect(x: 27, y: 0, width: 64, height: 65))
        let leftImageV = UIImageView(image: UIImage(named: "schedule_edit"))
        leftImageV.frame = CGRect(x: 15, y: 15, width: 23, height: 23)
        leftView1.addSubview(leftImageV)
        cont.leftView = leftView1
        cont.leftViewMode = .always
        cont.delegate = self
        return cont
    }()
    private lazy var startTimeView:UIView = {
        let cont = UIView()
        cont.backgroundColor = .white
        cont.layer.cornerRadius = 6
        cont.clipsToBounds = false
        cont.layerShadowColor = .rgba(233, 231, 241, 1)
        cont.layerShadowOffset = CGSize(width: 0, height: 2.5)
        cont.layerShadowOpacity = 1
        cont.layerShadowRadius = 7.5
        
        let startLabel = UILabel()
        startLabel.text = "开始"
        startLabel.textColor = .rgba(137, 137, 137, 1)
        startLabel.font = .regular(13)
        cont.addSubview(startLabel)
        startLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10.5)
            make.top.equalToSuperview().offset(12.5)
            make.height.equalTo(18.5)
        }
        
        cont.addSubview(startTimeLabel)
        startTimeLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(5.5)
            make.bottom.equalToSuperview().offset(-11.5)
            make.right.equalToSuperview().offset(-5)
            make.height.equalTo(22.5)
        }
        let tap = UITapGestureRecognizer(target: self, action: #selector(chooseTimeAction(vi:)))
        cont.addGestureRecognizer(tap)
        return cont
    }()
    private lazy var endTimeView:UIView = {
        let cont = UIView()
        cont.backgroundColor = .white
        cont.layer.cornerRadius = 6
        cont.clipsToBounds = false
        cont.layerShadowColor = .rgba(233, 231, 241, 1)
        cont.layerShadowOffset = CGSize(width: 0, height: 2.5)
        cont.layerShadowOpacity = 1
        cont.layerShadowRadius = 7.5
        
        let endLabel = UILabel()
        endLabel.text = "结束"
        endLabel.textColor = .rgba(137, 137, 137, 1)
        endLabel.font = .regular(13)
        cont.addSubview(endLabel)
        endLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10.5)
            make.top.equalToSuperview().offset(12.5)
            make.height.equalTo(18.5)
        }
        cont.addSubview(endTimeLabel)
        endTimeLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(5.5)
            make.bottom.equalToSuperview().offset(-11.5)
            make.right.equalToSuperview().offset(-5)
            make.height.equalTo(22.5)
        }
        let tap = UITapGestureRecognizer(target: self, action: #selector(chooseTimeAction(vi:)))
        cont.addGestureRecognizer(tap)
        return cont
    }()
    private lazy var startTimeLabel:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(51, 51, 51, 1)
        cont.font = .medium(16)
        cont.adjustsFontSizeToFitWidth = true
        return cont
    }()
    private lazy var endTimeLabel:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(51, 51, 51, 1)
        cont.font = .medium(16)
        cont.adjustsFontSizeToFitWidth = true
        return cont
    }()
    private lazy var allDaySwitchView:switchView = {
        let cont = switchView()
        cont.setInfo(imgName: "addSchedule_allDay", titleStr: "全天")
        cont.changeBlock = {[self] value in
            model.time_type = value == true ? 1 : 2
            if value == true{
                model.start_at = model.start_at.count > 0 ? String(model.start_at.prefix(10)) : ""
                model.end_at = model.end_at.count > 0 ? String(model.end_at.prefix(10)) : ""
            }else{
                model.start_at = model.start_at.count > 0 ? timeToAllTime(timeStr: model.start_at) : ""
                model.end_at = model.end_at.count > 0 ? timeToAllTime(timeStr: model.end_at) : ""
            }
            startTimeLabel.text = model.start_at
            endTimeLabel.text = model.end_at
        }
        return cont
    }()
    private lazy var backColorSwitchView:switchView = {
        let cont = switchView()
        cont.setInfo(imgName: "addSchedule_beijingse", titleStr: "背景色")
        cont.changeBlock = {[weak self] value in
            self?.model.is_color = value == true ? 1 : 0
        }
        return cont
    }()
    private lazy var selfSeeSwitchView:switchView = {
        let cont = switchView()
        cont.setInfo(imgName: "addSchedule_self", titleStr: "仅本人可见")
        cont.changeBlock = {[weak self] value in
            self?.model.self_visible = value == true ? 1 : 0
        }
        return cont
    }()
    private lazy var levelView:typesSelectView = {
        let cont = typesSelectView()
        cont.setInfo(imgName: "addSchedule_level", titleStr: "紧急程度")
        cont.selectBlock = {[weak self] in
            self?.present(self!.levelAlertCont, animated: true, completion: nil)
        }
        cont.contentSubLab.text = "默认"
        return cont
    }()
    private lazy var scheduleTypeVi:scheduleTypesSelectView = {
        let cont = scheduleTypesSelectView()
        cont.defaultSelectAction(model: model)
        cont.showBlock = {[weak self] in
            self?.scheduleTypeVi.snp.updateConstraints({ make in
                make.height.equalTo(SCALEWIDTH(190))
            })
        }
        cont.hideBlock = {[weak self] in
            self?.scheduleTypeVi.snp.updateConstraints({ make in
                make.height.equalTo(50)
            })
        }
        cont.selectBlock = {[weak self] value in
            self?.model.type = value
            switch value {
            case "线上会议":
                //线上会议
                self?.jueseView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                self?.huiyiPingtaiView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                self?.huiyihaoView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                self?.huichangView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                self?.jiangtiView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                self?.huiyiAdressView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                break
            case "线下会议":
                //线下会议
                self?.jueseView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                self?.huiyiPingtaiView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                self?.huiyihaoView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                self?.huichangView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                self?.jiangtiView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                self?.huiyiAdressView.snp.updateConstraints { make in
                    make.height.equalTo(50)
                }
                break
            default:
                self?.jueseView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                self?.huiyiPingtaiView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                self?.huiyihaoView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                self?.huichangView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                self?.jiangtiView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                self?.huiyiAdressView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                self?.huichangView.snp.updateConstraints { make in
                    make.height.equalTo(0)
                }
                break
            }
        }
        return cont
    }()
    private lazy var jueseView:scheduleJueseSelectView = {
        let cont = scheduleJueseSelectView()
        cont.defaultSelectAction(model: model)
        cont.showBlock = {[weak self] in
            self?.jueseView.snp.updateConstraints({ make in
                make.height.equalTo(SCALEWIDTH(190))
            })
        }
        cont.hideBlock = {[weak self] in
            self?.jueseView.snp.updateConstraints({ make in
                make.height.equalTo(50)
            })
        }
        cont.selectBlock = {[weak self] value in
            self?.model.task = value
        }
        return cont
    }()
    private lazy var huiyiAdressView:addScheduleInputView = {
        let cont = addScheduleInputView()
        cont.setInfo(imgName: "addSchedule_adress", titleStr: "会议地址")
        cont.inputBlock = {[weak self] value in
            self?.model.schedule_address = value
        }
        return cont
    }()
    private lazy var huiyiPingtaiView:typesSelectView = {
        let cont = typesSelectView()
        cont.setInfo(imgName: "addSchedule_pingtai", titleStr: "会议平台")
        cont.selectBlock = {[weak self] in
            self?.present(self!.pingtaiAlertCont, animated: true, completion: nil)
        }
        return cont
    }()
    private lazy var huiyihaoView:addScheduleInputView = {
        let cont = addScheduleInputView()
        cont.setInfo(imgName: "addSchedule_huiyihao", titleStr: "会议号")
        cont.inputBlock = {[weak self] value in
            self?.model.schedule_number = value
        }
        return cont
    }()
    private lazy var huichangView:addScheduleInputView = {
        let cont = addScheduleInputView()
        cont.setInfo(imgName: "addSchedule_huichang", titleStr: "会场")
        cont.inputBlock = {[weak self] value in
            self?.model.schedule_site = value
        }
        return cont
    }()
    private lazy var jiangtiView:addScheduleInputView = {
        let cont = addScheduleInputView()
        cont.setInfo(imgName: "addSchedule_jiangti", titleStr: "讲题")
        cont.inputBlock = {[weak self] value in
            self?.model.schedule_theme = value
        }
        return cont
    }()
    private lazy var remindView:typesSelectView = {
        let cont = typesSelectView()
        cont.setInfo(imgName: "addSchedule_remind", titleStr: "提醒")
        cont.selectBlock = {[weak self] in
            self?.present(self!.remindAlertCont, animated: true, completion: nil)
        }
        return cont
    }()
    private lazy var contentTextView:UITextView = {
        let cont = UITextView()
        cont.font = .regular(13)
        cont.text = "请输入日程内容"
        cont.delegate = self
        cont.textColor = .rgba(0, 0, 0)
        cont.backgroundColor = .clear
        return cont
    }()
    private lazy var collectionView: UICollectionView = {
        let layout = DGCollectionViewLeftAlignFlowLayout()
        layout.itemSize = CGSize(width: 80, height: 80)
        layout.sectionInset = .init(top: 13, left: 10, bottom: 13, right: 10)
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 17
        let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
        cv.delegate = self
        cv.dataSource = self
        cv.register(cellWithClass: MYGFeedBackCell.self)
        //cv.addObserver(self, forKeyPath: "contentSize", options: .new, context: nil)
        cv.backgroundColor = .clear
        cv.isScrollEnabled = false
        return cv
    }()
    private lazy var levelAlertCont:UIAlertController = {
        let alertController = UIAlertController(title: nil,
                                                message: nil, preferredStyle: .actionSheet)
        let okAction3 = UIAlertAction(title: "普通", style: .default, handler: {[weak self]
            action in
            self?.levelView.contentSubLab.text = "普通"
            self?.model.status = 2
            self?.levelView.contentSubLab.textColor = .rgba(51, 51, 51)
        })
        let okAction4 = UIAlertAction(title: "紧急", style: .default, handler: {[weak self]
            action in
            self?.levelView.contentSubLab.text = "紧急"
            self?.model.status = 1
            self?.levelView.contentSubLab.textColor = .rgba(51, 51, 51)
        })
        let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: {
            action in
        })
        alertController.addAction(okAction3)
        alertController.addAction(okAction4)
        alertController.addAction(cancelAction)

        return alertController
    }()
    private lazy var pingtaiAlertCont:UIAlertController = {
        let alertController = UIAlertController(title: nil,
                                                message: nil, preferredStyle: .actionSheet)
        let okAction3 = UIAlertAction(title: "腾讯会议", style: .default, handler: {[weak self]
            action in
            self?.huiyiPingtaiView.contentSubLab.text = "腾讯会议"
            self?.model.schedule_type = "腾讯会议"
            self?.huiyiPingtaiView.contentSubLab.textColor = .rgba(51, 51, 51)
        })
        let okAction4 = UIAlertAction(title: "zoom会议", style: .default, handler: {[weak self]
            action in
            self?.huiyiPingtaiView.contentSubLab.text = "zoom会议"
            self?.model.schedule_type = "zoom会议"
            self?.huiyiPingtaiView.contentSubLab.textColor = .rgba(51, 51, 51)
        })
        let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: {
            action in
        })
        alertController.addAction(okAction3)
        alertController.addAction(okAction4)
        alertController.addAction(cancelAction)
        return alertController
    }()
    private lazy var remindAlertCont:UIAlertController = {
        let alertController = UIAlertController(title: nil,
                                                message: nil, preferredStyle: .actionSheet)
        //        let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
        let okAction1 = UIAlertAction(title: "准时", style: .default, handler: {[weak self]
            action in
            self?.remindView.contentSubLab.text = "准时"
            self?.model.remind_time_desc = "准时"
            self?.remindView.contentSubLab.textColor = .rgba(51, 51, 51)
            self?.getRemindTimeStr(type: 1)
            self?.model.remind_time_type = 1
        })
        let okAction2 = UIAlertAction(title: "提前5分钟", style: .default, handler: {[weak self]
            action in
            self?.remindView.contentSubLab.text = "提前5分钟"
            self?.model.remind_time_desc = "提前5分钟"
            self?.remindView.contentSubLab.textColor = .rgba(51, 51, 51)
            self?.getRemindTimeStr(type: 2)
            self?.model.remind_time_type = 1
        })
        let okAction3 = UIAlertAction(title: "提前10分钟", style: .default, handler: {[weak self]
            action in
            self?.remindView.contentSubLab.text = "提前10分钟"
            self?.model.remind_time_desc = "提前10分钟"
            self?.remindView.contentSubLab.textColor = .rgba(51, 51, 51)
            self?.getRemindTimeStr(type: 3)
            self?.model.remind_time_type = 1
        })
        let okAction4 = UIAlertAction(title: "提前30分钟", style: .default, handler: {[weak self]
            action in
            self?.remindView.contentSubLab.text = "提前30分钟"
            self?.model.remind_time_desc = "提前30分钟"
            self?.remindView.contentSubLab.textColor = .rgba(51, 51, 51)
            self?.getRemindTimeStr(type: 4)
            self?.model.remind_time_type = 1
        })
        let okAction5 = UIAlertAction(title: "提前60分钟", style: .default, handler: {[weak self]
            action in
            self?.remindView.contentSubLab.text = "提前60分钟"
            self?.model.remind_time_desc = "提前60分钟"
            self?.remindView.contentSubLab.textColor = .rgba(51, 51, 51)
            self?.getRemindTimeStr(type: 5)
            self?.model.remind_time_type = 1
        })
        let okAction6 = UIAlertAction(title: "提前1天", style: .default, handler: {[weak self]
            action in
            self?.remindView.contentSubLab.text = "提前1天"
            self?.model.remind_time_desc = "提前1天"
            self?.remindView.contentSubLab.textColor = .rgba(51, 51, 51)
            self?.getRemindTimeStr(type: 6)
            self?.model.remind_time_type = 1
        })
        let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: {
            action in
        })
        alertController.addAction(okAction1)
        alertController.addAction(okAction2)
        alertController.addAction(okAction3)
        alertController.addAction(okAction4)
        alertController.addAction(okAction5)
        alertController.addAction(okAction6)
        alertController.addAction(cancelAction)
        return alertController
    }()
    private lazy var headImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "schedule_head")
        return cont
    }()
    private lazy var textNumLabel:UILabel = {
        let cont = UILabel()
        cont.font = .regular(13)
        cont.textColor = .rgba(204, 204, 204)
        cont.text = "0/200"
        return cont
    }()
    private lazy var sureBtn:UIButton = {
        let cont = UIButton()
        cont.titleLabel?.font = .medium(17)
        cont.setTitleColor(.white, for: .normal)
        cont.setTitle("确认", for: .normal)
        cont.backgroundColor = .rgba(89, 97, 245, 1)
        cont.layerCornerRadius = 20
        cont.addTarget(self, action: #selector(doneAction), for: .touchUpInside)
        return cont
    }()
}
extension MYGAddScheduleViewController:UITextFieldDelegate{
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let currentText = textField.text ?? ""
        let textToBeChanged = (currentText as NSString).replacingCharacters(in: range, with: string)
        print("实时输入的内容: \(textToBeChanged)")
        model.name = textToBeChanged
        return true
    }
    private func timeTozeroTime(timeStr:String) -> String{
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
        if let date = dateFormatter.date(from: timeStr) {
            let timestamp = date.timeIntervalSince1970
            let timeInterval:TimeInterval = TimeInterval(timestamp)
            let dateA = NSDate(timeIntervalSince1970: timeInterval)
            let dateformatter = DateFormatter()
            dateformatter.dateFormat = "yyyy-MM-dd" //自定义日期格式
            let time = dateformatter.string(from:dateA as Date)
            return time
        }
        return ""
    }
    private func timeToAllTime(timeStr:String) -> String{
        return "\(timeStr) 00:00"
    }
    private func getRemindTimeStr(type:Int){
        if (model.start_at.count == 0){
            MMYGHUD.showToast(text: "请选择开始时间")
            return
        }
        var timestamp = startTime.timeIntervalSince1970
        var str = ""
        let  dfmatter = DateFormatter()
        dfmatter.dateFormat = "yyyy-MM-dd HH:mm:ss"

        switch type {
        case 1:
            model.remind_date_5 = ""
            model.remind_date_10 = ""
            model.remind_date_30 = ""
            model.remind_date_60 = ""
            model.remind_date_one_day = ""
            var date = NSDate(timeIntervalSince1970: timestamp)
            str = dfmatter.string(from: date as Date)
            model.remind_date_time = str
            break
        case 2:
            timestamp = timestamp - 300
            var date = NSDate(timeIntervalSince1970: timestamp)
            str = dfmatter.string(from: date as Date)
            model.remind_date_5 = str
            model.remind_date_10 = ""
            model.remind_date_30 = ""
            model.remind_date_60 = ""
            model.remind_date_one_day = ""
            model.remind_date_time = ""
            break
        case 3:
            timestamp = timestamp - 600
            var date = NSDate(timeIntervalSince1970: timestamp)
            str = dfmatter.string(from: date as Date)
            model.remind_date_5 = ""
            model.remind_date_10 = str
            model.remind_date_30 = ""
            model.remind_date_60 = ""
            model.remind_date_one_day = ""
            model.remind_date_time = ""
            break
        case 4:
            timestamp = timestamp - 1800
            var date = NSDate(timeIntervalSince1970: timestamp)
            str = dfmatter.string(from: date as Date)
            model.remind_date_5 = ""
            model.remind_date_10 = ""
            model.remind_date_30 = str
            model.remind_date_60 = ""
            model.remind_date_one_day = ""
            model.remind_date_time = ""
            break
        case 5:
            timestamp = timestamp - 3600
            var date = NSDate(timeIntervalSince1970: timestamp)
            str = dfmatter.string(from: date as Date)
            model.remind_date_5 = ""
            model.remind_date_10 = ""
            model.remind_date_30 = ""
            model.remind_date_60 = str
            model.remind_date_one_day = ""
            model.remind_date_time = ""
            break
        case 6:
            timestamp = timestamp - 24*60*60
            var date = NSDate(timeIntervalSince1970: timestamp)
            str = dfmatter.string(from: date as Date)
            model.remind_date_5 = ""
            model.remind_date_10 = ""
            model.remind_date_30 = ""
            model.remind_date_60 = ""
            model.remind_date_one_day = str
            model.remind_date_time = ""
            break
        default:
            break
        }
    }
}
extension MYGAddScheduleViewController: UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//        contents.count == 0 ? 1 : contents.count + 1
        1
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withClass: MYGFeedBackCell.self, for: indexPath)
        if (model.imageStrArr.count > 0) {
            cell.imageView.sd_setImage(with: URL(string: model.imageStrArr[0]))
        } else {
            cell.imageView.image = UIImage(named: "Photo_date")
        }
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        //        if indexPath.row == contents.count {
        selectPhoto()
        //        }
    }
    
    private func selectPhoto() {
        let pick = TZImagePickerController(maxImagesCount: 1, delegate: self)!
        pick.maxImagesCount = 1
        self.present(pick, animated: true)
    }
    
    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        guard let keyPath = keyPath, keyPath == "contentSize" else {
            return
        }
        
        self.collectionView.snp.remakeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(contentTextView.snp.bottom)
            make.bottom.equalToSuperview()
            make.height.equalTo(self.collectionView.contentSize.height)
        }
    }
}

extension MYGAddScheduleViewController: TZImagePickerControllerDelegate {
    func imagePickerController(_ picker: TZImagePickerController!, didFinishPickingPhotos photos: [UIImage]!, sourceAssets assets: [Any]!, isSelectOriginalPhoto: Bool, infos: [[AnyHashable : Any]]!) {

//        view.layoutIfNeeded()
//        self.collectionView.snp.updateConstraints { make in
//            make.height.equalTo(self.collectionView.contentSize.height)
//        }
        MYGNetwork<MYGSocketAPI, MYGUploadFileModel>.request(target: .uploadFile(image: photos[0])) { result in
            self.model.image = "[\(result.fullurl)]"
            self.model.imageStrArr = [result.fullurl]
            self.contents.removeAll()
            self.contents.append(result.fullurl)
            self.collectionView.reloadData()
        } failed: { _, error in
            MMYGHUD.showToast(text: error)
        }
    }
    func getShowTimeByDate(date:Date) -> String{
        let dateformatter = DateFormatter()
        dateformatter.dateFormat = "yyyy-MM-dd HH:mm"
//        let mmformatter = DateFormatter()
//        mmformatter.dateFormat = "mm"
//        let formatterHour = DateFormatter()
//        formatterHour.dateFormat = "hh"
//        let hourStr = formatterHour.string(from: date)
        let dateString = dateformatter.string(from: date)
//        let mmdateString = mmformatter.string(from: date)
        return dateString

//        if hourStr.int ?? 0 < 13{
//            let dateString = dateformatter.string(from: date)
//            let mmdateString = mmformatter.string(from: date)
//            return "\(dateString) \(hourStr):\(mmdateString) AM"
//        }else{
//            let dateString = dateformatter.string(from: date)
//            let mmdateString = mmformatter.string(from: date)
//            let hInt:Int = hourStr.int ?? 0
//            return "\(dateString) \(hInt - 12):\(mmdateString) PM"
//        }
    }
    func getstartEndByDate(date:Date) -> String{
        let mmformatter = DateFormatter()
        mmformatter.dateFormat = "mm"
        let formatterHour = DateFormatter()
        formatterHour.dateFormat = "hh"
        let hourStr = formatterHour.string(from: date)
        if hourStr.int ?? 0 < 13{
            let mmdateString = formatterHour.string(from: date)
            return "\(hourStr):\(mmdateString) AM"
        }else{
            let mmdateString = mmformatter.string(from: date)
            let hInt:Int = hourStr.int ?? 0
            return "\(hInt - 12):\(mmdateString) PM"
        }
    }
    func getUpdateTimeByDate(date:Date) -> String{
        let dateformatter = DateFormatter()
        dateformatter.dateFormat = "YYYY-MM-dd"
        let hourStr = dateformatter.string(from: date)
        return hourStr
    }
    func getUpdateTimehhmmByDate(date:Date) -> String{
        let dateformatter = DateFormatter()
        dateformatter.dateFormat = "YYYY-MM-dd HH:mm"
        let hourStr = dateformatter.string(from: date)
        return hourStr
    }
    @objc func chooseTimeAction(vi:UITapGestureRecognizer){
        if vi.view == startTimeView{
            self.popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
                let actionSheet = dateAndTimeSelectView()
                actionSheet.dismissBlock = {[weak self] value in
                    self?.startTimeLabel.text = self?.getShowTimeByDate(date: value)
                    self?.startTime = value
                    self?.model.start_at = self?.getUpdateTimehhmmByDate(date: value) ?? ""
                    self?.model.set_date = self?.getUpdateTimeByDate(date: value) ?? ""
                    self?.popup.dismissPopup()
                }
                actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight)
                return actionSheet
            }
        }else{
            self.popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
                let actionSheet = dateAndTimeSelectView()
                actionSheet.dismissBlock = {[weak self] value in
                    self?.endTimeLabel.text = self?.getShowTimeByDate(date: value)
                    self?.endTime = value
                    self?.model.end_at = self?.getUpdateTimehhmmByDate(date: value) ?? ""
                    self?.popup.dismissPopup()
                }
                actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight)
                return actionSheet
            }
        }
        
    }
}

extension MYGAddScheduleViewController:UITextViewDelegate{
    func textViewDidEndEditing(_ textView: UITextView) {
        if textView.text.count == 0{
            textView.text = "请输入日程内容"
            textView.textColor = .rgba(204, 204, 204)
        }
    }
    func textViewDidBeginEditing(_ textView: UITextView) {
        if textView.text == "请输入日程内容"{
            textView.text = ""
            textView.textColor = .rgba(51, 51, 51)
        }
    }
    func textViewDidChange(_ textView: UITextView) {
        let currentCharacterCount = textView.text.count
        
        if currentCharacterCount > 200 {
            let substring = textView.text.prefix(200)
            textView.text = String(substring)
        }
        model.describe = textView.text
        textNumLabel.text = "\(textView.text.count)/200"
    }
}

class dateAndTimeSelectView:UIView{
    var dismissBlock:((Date) -> ())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        layer.masksToBounds = true
        addSubview(whiteView)
        whiteView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(230)
        }
        addSubview(datePicker)
        datePicker.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(200)
        }
        whiteView.addSubview(finishBtn)
        finishBtn.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-10)
            make.top.equalToSuperview()
            make.height.equalTo(30)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private lazy var datePicker:UIDatePicker = {
        let cont = UIDatePicker()
        cont.datePickerMode = .dateAndTime
        if #available(iOS 13.4, *) {
            cont.preferredDatePickerStyle = .wheels
        } else {
            // Fallback on earlier versions
        }
        cont.minimumDate = Date()
        cont.locale = Locale(identifier: "zh_CN")
        cont.backgroundColor = .white
        return cont
    }()
    private lazy var whiteView:UIView = {
        let cont = UIView()
        cont.backgroundColor = .white
        return cont
    }()
    private lazy var finishBtn:UIButton = {
        let cont = UIButton()
        cont.setTitle("确定", for: .normal)
        cont.titleLabel?.font = .regular(15)
        cont.setTitleColor(.rgba(51, 51, 51), for: .normal)
        cont.addTarget(self, action: #selector(doneDateSelect), for: .touchUpInside)
        return cont
    }()
    @objc func doneDateSelect(){
        if dismissBlock != nil {
            dismissBlock!(datePicker.date)
        }
    }
}
class switchView:UIView{
    var changeBlock:((Bool) -> ())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUIs()
    }
    private func initUIs(){
        layer.masksToBounds = true
        addSubview(switchImageV)
        switchImageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(25)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 18, height: 18))
        }
        addSubview(switchTitleLabel)
        switchTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(switchImageV.snp.right).offset(12.5)
            make.centerY.equalToSuperview()
            make.height.equalTo(22.5)
        }
        addSubview(switchBtn)
        switchBtn.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-20)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 40, height: 23))
        }
    }
    func setInfo(imgName:String,titleStr:String){
        switchImageV.image = UIImage(named: imgName)
        switchTitleLabel.text = titleStr
        
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private lazy var switchImageV:UIImageView = {
        let cont = UIImageView()
        return cont
    }()
    private lazy var switchTitleLabel:UILabel = {
        let cont = UILabel()
        cont.font = .medium(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.text = ""
        return cont
    }()
    lazy var switchBtn:UIButton = {
        let cont = UIButton()
        cont.setImage(UIImage(named: "addSchedule_switchClose"), for: .normal)
        cont.setImage(UIImage(named: "addSchedule_switchOpen"), for: .selected)
        cont.addTarget(self, action: #selector(switchAction(switchButton:)), for: .touchUpInside)
        return cont
    }()
    @objc func switchAction(switchButton: UIButton) {
        if switchButton.isSelected {
            print("开关已关闭")
            switchBtn.isSelected = false
        } else {
            print("开关已打开")
            switchBtn.isSelected = true
        }
        if changeBlock != nil{
            self.changeBlock!(switchButton.isSelected)
        }
    }
}
class typesSelectView:UIView{
    var selectBlock:(() -> ())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUIs()
        let tap = UITapGestureRecognizer(target: self, action: #selector(changeData))
        self.addGestureRecognizer(tap)
    }
    private func initUIs(){
        layer.masksToBounds = true
        addSubview(switchImageV)
        switchImageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(25)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 18, height: 18))
        }
        addSubview(switchTitleLabel)
        switchTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(switchImageV.snp.right).offset(12.5)
            make.centerY.equalToSuperview()
            make.height.equalTo(22.5)
        }
        addSubview(arrowIcon)
        arrowIcon.snp.makeConstraints { make in
            make.right.equalTo(-35)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 7, height: 12))
        }
        addSubview(contentSubLab)
        contentSubLab.snp.makeConstraints { make in
            make.right.equalTo(arrowIcon.snp.left).offset(-10)
            make.centerY.equalToSuperview()
            make.height.equalTo(25)
        }
    }
    func setInfo(imgName:String,titleStr:String){
        switchImageV.image = UIImage(named: imgName)
        switchTitleLabel.text = titleStr
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private lazy var switchImageV:UIImageView = {
        let cont = UIImageView()
        return cont
    }()
    private lazy var switchTitleLabel:UILabel = {
        let cont = UILabel()
        cont.font = .medium(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.text = ""
        return cont
    }()
    private lazy var arrowIcon: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "MYG_cloudDisk_share_arrowRight"))
        return imageV
    }()
    lazy var contentSubLab:UILabel = {
        let cont = UILabel()
        cont.textColor = .rgba(204, 204, 204)
        cont.font = .regular(16)
        return cont
    }()
    @objc private func changeData(){
        if selectBlock != nil{
            selectBlock!()
        }
    }
}
class scheduleTypesSelectView:UIView{
    var showBlock:(() -> ())?
    var hideBlock:(() -> ())?
    var selectBlock:((String) -> ())?
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUIs()
    }
//    func showOldType(str:String){
//        let typesArr = ["手术","线上会议","线下会议","培训","休假","待办","出差","自定义"]
//        var btn = self.view
//        if let index = typesArr.firstIndex(of: str) {
//
//        } else {
//        }
//        scheduleSelectImageV.removeFromSuperview()
//        btn.addSubview(scheduleSelectImageV)
//        scheduleSelectImageV.snp.makeConstraints { make in
//            make.top.right.equalToSuperview()
//            make.size.equalTo(CGSize(width: 12.5, height: 10.5))
//        }
//    }
    @objc private func typeSelectAction(btn:UIButton){
        let typesArr = ["手术","线上会议","线下会议","培训","休假","待办","出差"]
        if typesArr.firstIndex(of: btn.titleLabel?.text ?? "") != nil {
            if selectBlock != nil{
                selectBlock!(btn.titleLabel?.text ?? "")
            }
        }else{
            self.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
                let alert = scheduleTypeCustomView()
                alert.selectBlock = {[weak self] text in
                    btn.setTitle(text, for: .normal)
                    if self?.selectBlock != nil{
                        self?.selectBlock!(text)
                    }
                    self?.rootResponsder().popup.dismissPopup()
                }
                alert.dismissBlock = {[weak self] in
                    self?.rootResponsder().popup.dismissPopup()
                }
                alert.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight)
                return alert
            }
        }
//        if btn.titleLabel?.text == "自定义" {
//            self.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
//                let alert = scheduleTypeCustomView()
//                alert.selectBlock = {[weak self] text in
//                    btn.setTitle(text, for: .normal)
//                    if self?.selectBlock != nil{
//                        self?.selectBlock!(text)
//                    }
//                    self?.rootResponsder().popup.dismissPopup()
//                }
//                alert.dismissBlock = {[weak self] in
//                    self?.rootResponsder().popup.dismissPopup()
//                }
//                alert.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight)
//                return alert
//            }
//        }else{
//            if selectBlock != nil{
//                selectBlock!(btn.titleLabel?.text ?? "")
//            }
//        }


        scheduleSelectImageV.removeFromSuperview()
        btn.addSubview(scheduleSelectImageV)
        scheduleSelectImageV.snp.makeConstraints { make in
            make.top.right.equalToSuperview()
            make.size.equalTo(CGSize(width: 12.5, height: 10.5))
        }
    }
    func defaultSelectAction(model:MYGScheduleListModel){
        scheduleSelectImageV.removeFromSuperview()
        let typesArr = ["手术","线上会议","线下会议","培训","休假","待办","出差","自定义"]
        if let index = typesArr.firstIndex(of: model.type) {
            for ind in 0...typesArr.count - 1 {
                if typesArr[ind] == model.type {
                    let btn:UIButton = self.viewWithTag(ind + 1)! as! UIButton
                    btn.addSubview(scheduleSelectImageV)
                    scheduleSelectImageV.snp.makeConstraints { make in
                        make.top.right.equalToSuperview()
                        make.size.equalTo(CGSize(width: 12.5, height: 10.5))
                    }
                }
            }
        }else{
            let btn:UIButton = self.viewWithTag(8)! as! UIButton
            btn.setTitle(model.type, for: .normal)
            btn.addSubview(scheduleSelectImageV)
            scheduleSelectImageV.snp.makeConstraints { make in
                make.top.right.equalToSuperview()
                make.size.equalTo(CGSize(width: 12.5, height: 10.5))
            }
        }

    }
    @objc private func showTypes(btn:UIButton){
        if btn.isSelected == false{
            if showBlock != nil{
                showBlock!()
            }
            btn.isSelected = true
        }else{
            if hideBlock != nil{
                hideBlock!()
            }
            btn.isSelected = false
        }
        
    }
    private func initUIs(){
        self.layer.masksToBounds = true
        addSubviews([scheduleTypesImageV,scheduleTypesTitleLabel,scheduleTypesarrowIcon])
        scheduleTypesImageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(25)
            make.top.equalToSuperview().offset(13)
            make.size.equalTo(CGSize(width: 18, height: 18))
        }
        scheduleTypesTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(scheduleTypesImageV.snp.right).offset(12.5)
            make.centerY.equalTo(scheduleTypesImageV)
            make.height.equalTo(22.5)
        }
        scheduleTypesarrowIcon.snp.makeConstraints { make in
            make.right.equalTo(-35)
            make.centerY.equalTo(scheduleTypesImageV)
            make.size.equalTo(CGSize(width: 12, height: 12))
        }
        let typesArr = ["手术","线上会议","线下会议","培训","休假","待办","出差","自定义"]
        let colorArr = [RGBA(r: 0, g: 153, b: 255, a: 0.31),RGBA(r: 45, g: 199, b: 109, a: 0.15),RGBA(r: 255, g: 122, b: 82, a: 0.12),RGBA(r: 117, g: 64, b: 238, a: 0.09),RGBA(r: 255, g: 0, b: 0, a: 0.14),RGBA(r: 219, g: 151, b: 27, a: 0.13),RGBA(r: 152, g: 230, b: 37, a: 0.24),RGBA(r: 0, g: 255, b: 237, a: 0.12)]
        for ind in 0...7{
            let btn = UIButton()
            btn.backgroundColor = colorArr[ind]
            btn.setTitle(typesArr[ind], for: .normal)
            btn.setTitleColor(.rgba(51, 51, 51), for: .normal)
            btn.titleLabel?.font = .regular(14)
            btn.layerCornerRadius = 8
            btn.tag = ind + 1
            btn.addTarget(self, action: #selector(typeSelectAction(btn:)), for: .touchUpInside)
            addSubview(btn)
            btn.snp.makeConstraints { make in
                make.left.equalToSuperview().offset(SCALEWIDTH(100) + SCALEWIDTH(88)*CGFloat((ind%3)))
                make.top.equalTo(scheduleTypesTitleLabel.snp.bottom).offset(18 + SCALEWIDTH(47)*CGFloat((ind/3)))
                make.size.equalTo(CGSize(width: SCALEWIDTH(68), height: SCALEWIDTH(32)))
            }
            if ind == 0{
                btn.addSubview(scheduleSelectImageV)
                scheduleSelectImageV.snp.makeConstraints { make in
                    make.top.right.equalToSuperview()
                    make.size.equalTo(CGSize(width: 12.5, height: 10.5))
                }
            }
        }
    }
    private lazy var scheduleTypesImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "addSchedule_scheduleType")
        return cont
    }()
    private lazy var scheduleSelectImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "addSchedule_select")
        return cont
    }()
    private lazy var scheduleTypesTitleLabel:UILabel = {
        let cont = UILabel()
        cont.font = .medium(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.text = "日程类型"
        return cont
    }()
    private lazy var scheduleTypesarrowIcon: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "MYG_cloudDisk_share_arrowRight"), for: .normal)
        btn.setImage(UIImage(named: "MYG_cloudDisk_arrow_down"), for: .selected)
        btn.addTarget(self, action: #selector(showTypes(btn:)), for: .touchUpInside)
        return btn
    }()
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
class scheduleJueseSelectView:UIView{
    var showBlock:(() -> ())?
    var hideBlock:(() -> ())?
    var selectBlock:((String) -> ())?

    override init(frame: CGRect) {
        super.init(frame: frame)
        initUIs()
    }
    @objc private func typeSelectAction(btn:UIButton){
        let typesArr = ["主席","主持","讲者","术者","嘉宾","颁奖者","领奖者","讨论嘉宾","致辞","会议总结"]
        if typesArr.firstIndex(of: btn.titleLabel?.text ?? "") != nil {
            if selectBlock != nil{
                selectBlock!(btn.titleLabel?.text ?? "")
            }
        }else{
            self.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
                let alert = scheduleJueseCustomView()
                alert.selectBlock = {[weak self] text in
                    btn.setTitle(text, for: .normal)
                    if self?.selectBlock != nil{
                        self?.selectBlock!(text)
                    }
                    self?.rootResponsder().popup.dismissPopup()
                }
                alert.dismissBlock = {[weak self] in
                    self?.rootResponsder().popup.dismissPopup()
                }
                alert.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight)
                return alert
            }
        }
        
//        if btn.titleLabel?.text == "自定义" {
//            self.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
//                let alert = scheduleJueseCustomView()
//                alert.selectBlock = {[weak self] text in
//                    btn.setTitle(text, for: .normal)
//                    if self?.selectBlock != nil{
//                        self?.selectBlock!(text)
//                    }
//                    self?.rootResponsder().popup.dismissPopup()
//                }
//                alert.dismissBlock = {[weak self] in
//                    self?.rootResponsder().popup.dismissPopup()
//                }
//                alert.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: screenHeight)
//                return alert
//            }
//        }else{
//            if selectBlock != nil{
//                selectBlock!(btn.titleLabel?.text ?? "")
//            }
//        }
        scheduleSelectImageV.removeFromSuperview()
        btn.addSubview(scheduleSelectImageV)
        scheduleSelectImageV.snp.makeConstraints { make in
            make.top.right.equalToSuperview()
            make.size.equalTo(CGSize(width: 12.5, height: 10.5))
        }
    }
    @objc private func showTypes(btn:UIButton){
        if btn.isSelected == false{
            if showBlock != nil{
                showBlock!()
            }
            btn.isSelected = true
        }else{
            if hideBlock != nil{
                hideBlock!()
            }
            btn.isSelected = false
        }
        
    }
    func defaultSelectAction(model:MYGScheduleListModel){
        scheduleSelectImageV.removeFromSuperview()
        let typesArr = ["主席","主持","讲者","术者","嘉宾","颁奖者","领奖者","讨论嘉宾","致辞","会议总结","自定义"]
        if let index = typesArr.firstIndex(of: model.task) {
            for ind in 0...typesArr.count - 1 {
                if typesArr[ind] == model.task {
                    let btn:UIButton = self.viewWithTag(ind + 1)! as! UIButton
                    btn.addSubview(scheduleSelectImageV)
                    scheduleSelectImageV.snp.makeConstraints { make in
                        make.top.right.equalToSuperview()
                        make.size.equalTo(CGSize(width: 12.5, height: 10.5))
                    }
                }
            }
        }else{
            let btn:UIButton = self.viewWithTag(11)! as! UIButton
            btn.setTitle(model.task, for: .normal)
            btn.addSubview(scheduleSelectImageV)
            scheduleSelectImageV.snp.makeConstraints { make in
                make.top.right.equalToSuperview()
                make.size.equalTo(CGSize(width: 12.5, height: 10.5))
            }
        }

    }
    private func initUIs(){
        self.layer.masksToBounds = true
        addSubviews([scheduleTypesImageV,scheduleTypesTitleLabel,scheduleTypesarrowIcon])
        scheduleTypesImageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(25)
            make.top.equalToSuperview().offset(13)
            make.size.equalTo(CGSize(width: 18, height: 18))
        }
        scheduleTypesTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(scheduleTypesImageV.snp.right).offset(12.5)
            make.centerY.equalTo(scheduleTypesImageV)
            make.height.equalTo(22.5)
        }
        scheduleTypesarrowIcon.snp.makeConstraints { make in
            make.right.equalTo(-35)
            make.centerY.equalTo(scheduleTypesImageV)
            make.size.equalTo(CGSize(width: 12, height: 12))
        }
        let typesArr = ["主席","主持","讲者","术者","嘉宾","颁奖者","领奖者","讨论嘉宾","致辞","会议总结","自定义"]
        let colorArr = [RGBA(r: 0, g: 153, b: 255, a: 0.31),RGBA(r: 45, g: 199, b: 109, a: 0.15),RGBA(r: 255, g: 122, b: 82, a: 0.12),RGBA(r: 117, g: 64, b: 238, a: 0.09),RGBA(r: 255, g: 0, b: 0, a: 0.14),RGBA(r: 219, g: 151, b: 27, a: 0.13),RGBA(r: 152, g: 230, b: 37, a: 0.24),RGBA(r: 0, g: 255, b: 237, a: 0.12),RGBA(r: 219, g: 151, b: 27, a: 0.13),RGBA(r: 152, g: 230, b: 37, a: 0.24),RGBA(r: 0, g: 255, b: 237, a: 0.12)]
        for ind in 0...10{
            let btn = UIButton()
            btn.backgroundColor = colorArr[ind]
            btn.setTitle(typesArr[ind], for: .normal)
            btn.setTitleColor(.rgba(51, 51, 51), for: .normal)
            btn.titleLabel?.font = .regular(14)
            btn.layerCornerRadius = 8
            btn.tag = ind + 1
            btn.addTarget(self, action: #selector(typeSelectAction(btn:)), for: .touchUpInside)
            addSubview(btn)
            btn.snp.makeConstraints { make in
                make.left.equalToSuperview().offset(SCALEWIDTH(60) + SCALEWIDTH(78)*CGFloat((ind%4)))
                make.top.equalTo(scheduleTypesTitleLabel.snp.bottom).offset(18 + SCALEWIDTH(47)*CGFloat((ind/4)))
                make.size.equalTo(CGSize(width: SCALEWIDTH(68), height: SCALEWIDTH(32)))
            }
            if ind == 0{
                btn.addSubview(scheduleSelectImageV)
                scheduleSelectImageV.snp.makeConstraints { make in
                    make.top.right.equalToSuperview()
                    make.size.equalTo(CGSize(width: 12.5, height: 10.5))
                }
            }
        }
    }
    private lazy var scheduleTypesImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "addSchedule_juese")
        return cont
    }()
    private lazy var scheduleSelectImageV:UIImageView = {
        let cont = UIImageView()
        cont.image = UIImage(named: "addSchedule_select")
        return cont
    }()
    private lazy var scheduleTypesTitleLabel:UILabel = {
        let cont = UILabel()
        cont.font = .medium(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.text = "角色/任务"
        return cont
    }()
    private lazy var scheduleTypesarrowIcon: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "MYG_cloudDisk_share_arrowRight"), for: .normal)
        btn.setImage(UIImage(named: "MYG_cloudDisk_arrow_down"), for: .selected)
        btn.addTarget(self, action: #selector(showTypes(btn:)), for: .touchUpInside)
        return btn
    }()
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
class addScheduleInputView:UIView,UITextFieldDelegate{
    var inputBlock:((String) -> ())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initUIs()
    }
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let currentText = textField.text ?? ""
        let textToBeChanged = (currentText as NSString).replacingCharacters(in: range, with: string)
        print("实时输入的内容: \(textToBeChanged)")
        if inputBlock != nil{
            inputBlock!(textToBeChanged)
        }
        return true
    }
    private func initUIs(){
        layer.masksToBounds = true
        addSubview(switchImageV)
        switchImageV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(25)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize(width: 18, height: 18))
        }
        addSubview(switchTitleLabel)
        switchTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(switchImageV.snp.right).offset(12.5)
            make.centerY.equalToSuperview()
            make.height.equalTo(22.5)
        }
        addSubview(inputTf)
        inputTf.snp.makeConstraints { make in
            make.right.equalTo(-35)
            make.centerY.equalToSuperview()
            make.left.equalTo(switchTitleLabel.snp.right).offset(20)
            make.height.equalTo(22.5)
        }
    }
    func setInfo(imgName:String,titleStr:String){
        switchImageV.image = UIImage(named: imgName)
        switchTitleLabel.text = titleStr
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private lazy var switchImageV:UIImageView = {
        let cont = UIImageView()
        return cont
    }()
    private lazy var switchTitleLabel:UILabel = {
        let cont = UILabel()
        cont.font = .medium(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.text = ""
        return cont
    }()
    lazy var inputTf: UITextField = {
        let cont = UITextField()
        cont.textAlignment = .right
        cont.font = .regular(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.placeholder = "请输入"
        cont.delegate = self
        return cont
    }()
}
class scheduleTypeCustomView:UIView{
    var selectBlock:((String) -> ())?
    var dismissBlock:(() -> ())?

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .rgba(0, 0, 0,0.4)
        
        addSubview(whiteBackV)
        whiteBackV.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.left.equalToSuperview().offset(30)
            make.right.equalToSuperview().offset(-30)
            make.height.equalTo(170)
        }
        
        whiteBackV.addSubview(titleLab)
        titleLab.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(20)
            make.height.equalTo(20)
        }
        whiteBackV.addSubview(inputTf)
        inputTf.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-50)
            make.top.equalTo(titleLab.snp.bottom).offset(15)
            make.height.equalTo(30)
        }
        whiteBackV.addSubview(deleteBtn)
        deleteBtn.snp.makeConstraints { make in
            make.left.equalTo(inputTf.snp.right).offset(5)
            make.centerY.equalTo(inputTf)
            make.size.equalTo(CGSize(width: 25, height: 25))
        }
        whiteBackV.addSubview(sureBtn)
        sureBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.top.equalTo(inputTf.snp.bottom).offset(20)
            make.height.equalTo(40)
        }
        addSubview(closeBtn)
        closeBtn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(whiteBackV.snp.bottom).offset(20)
            make.size.equalTo(CGSize(width: 25, height: 25))
        }
        
    }
    @objc func deleteAction(){
        inputTf.text = ""
    }
    @objc func dismissAction(){
        if dismissBlock != nil{
            dismissBlock!()
        }
    }
    @objc func doneAction(){
        if inputTf.text?.count ?? 0 > 0{
            if selectBlock != nil{
                selectBlock!(inputTf.text ?? "")
            }
        }else{
            MMYGHUD.showToast(text: "请输入名称")
        }
    }
    private lazy var whiteBackV:UIView = {
        let cont = UIView()
        cont.backgroundColor = .white
        cont.layerCornerRadius = 5
        return cont
    }()
    private lazy var titleLab:UILabel = {
        let cont = UILabel()
        cont.font = .medium(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.text = "日程类型"
        return cont
    }()
    lazy var inputTf: UITextField = {
        let cont = UITextField()
        cont.font = .regular(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.placeholder = "请输入日程类型"
        return cont
    }()
    lazy var deleteBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "Find/close"), for: .normal)
        btn.addTarget(self, action: #selector(deleteAction), for: .touchUpInside)
        return btn
    }()
    lazy var sureBtn: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = .rgba(125, 113, 245)
        btn.addTarget(self, action: #selector(doneAction), for: .touchUpInside)
        btn.setTitle("确定", for: .normal)
        
        btn.layerCornerRadius = 20
        return btn
    }()
    lazy var closeBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "close"), for: .normal)
        btn.addTarget(self, action: #selector(dismissAction), for: .touchUpInside)
        return btn
    }()
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
class scheduleJueseCustomView:UIView{
    var selectBlock:((String) -> ())?
    var dismissBlock:(() -> ())?

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = .rgba(0, 0, 0,0.4)
        
        addSubview(whiteBackV)
        whiteBackV.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.left.equalToSuperview().offset(30)
            make.right.equalToSuperview().offset(-30)
            make.height.equalTo(170)
        }
        
        whiteBackV.addSubview(titleLab)
        titleLab.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(20)
            make.height.equalTo(20)
        }
        whiteBackV.addSubview(inputTf)
        inputTf.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-50)
            make.top.equalTo(titleLab.snp.bottom).offset(15)
            make.height.equalTo(30)
        }
        whiteBackV.addSubview(deleteBtn)
        deleteBtn.snp.makeConstraints { make in
            make.left.equalTo(inputTf.snp.right).offset(5)
            make.centerY.equalTo(inputTf)
            make.size.equalTo(CGSize(width: 25, height: 25))
        }
        whiteBackV.addSubview(sureBtn)
        sureBtn.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.top.equalTo(inputTf.snp.bottom).offset(20)
            make.height.equalTo(40)
        }
        addSubview(closeBtn)
        closeBtn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(whiteBackV.snp.bottom).offset(20)
            make.size.equalTo(CGSize(width: 25, height: 25))
        }
        
    }
    @objc func deleteAction(){
        inputTf.text = ""
    }
    @objc func dismissAction(){
        if dismissBlock != nil{
            dismissBlock!()
        }
    }
    @objc func doneAction(){
        if inputTf.text?.count ?? 0 > 0{
            if selectBlock != nil{
                selectBlock!(inputTf.text ?? "")
            }
        }else{
            MMYGHUD.showToast(text: "请输入角色/任务")
        }
    }
    private lazy var whiteBackV:UIView = {
        let cont = UIView()
        cont.backgroundColor = .white
        cont.layerCornerRadius = 5
        return cont
    }()
    private lazy var titleLab:UILabel = {
        let cont = UILabel()
        cont.font = .medium(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.text = "角色/任务"
        return cont
    }()
    lazy var inputTf: UITextField = {
        let cont = UITextField()
        cont.font = .regular(16)
        cont.textColor = .rgba(51, 51, 51)
        cont.placeholder = "请输入角色/任务"
        return cont
    }()
    lazy var deleteBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "Find/close"), for: .normal)
        btn.addTarget(self, action: #selector(deleteAction), for: .touchUpInside)
        return btn
    }()
    lazy var sureBtn: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = .rgba(125, 113, 245)
        btn.addTarget(self, action: #selector(doneAction), for: .touchUpInside)
        btn.setTitle("确定", for: .normal)
        
        btn.layerCornerRadius = 20
        return btn
    }()
    lazy var closeBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "close"), for: .normal)
        btn.addTarget(self, action: #selector(dismissAction), for: .touchUpInside)
        return btn
    }()
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
